(C) 1996 AROS - The Amiga Replacement OS


NAME
#include <proto/dos.h>
struct RDArgs * ReadArgs()
SYNOPSIS
STRPTR template
IPTR * array
struct RDArgs * rdargs

LOCATION
In DOSBase at offset 133
FUNCTION
Parses the commandline, a given string or Input() and fills an argument array according to the options template given. The array must be initialized to the wanted defaults before each call to ReadArgs(). If the rdargs argument is NULL ReadArgs() tries to parse the commandline and continues on the input channel if it just consists of a single '?', prompting the user for input.

INPUTS
template
Template string. The template string is given as a number of options separated by ',' and modified by '/' modifiers, e.g. 'NAME,WIDTH/N,HEIGHT/N' means get a name string and two numbers (width and height). The possible modifiers are: /S Option is a switch. It may be either set or left out. /T Option is a boolean value. Requires an argument which may be "ON", "YES" (setting the respective argument to 1), "OFF" or "NO" (setting the respective argument to 0). /N Option is a number. Strings are not allowed. If the option is optional, a pointer to the actual number is returned. This is how you know if it was really given. /A Argument is required. If it is left out ReadArgs() fails. /K The keyword must be given when filling the option. Normally it's skipped. /M Multiple strings. The result is returned as a string pointer array terminated with NULL. /M eats all strings that don't fit into any other option. If there are unfilled /A arguments after parsing they steal strings from /M. This makes it possible to e.g. write a COPY template like 'FROM/A/M,TO/A'. There may be only one /M option in a template. /F Eats the rest of the line even if there are option keywords in it.
array
Array to be filled with the result values. The array must be intialized to the default values before calling ReadArgs().
rdargs
An optional RDArgs structure determinating the type of input to process.
RESULT
A handle for the memory allocated by ReadArgs(). Must be freed with FreeArgs() later.

NOTES
EXAMPLE
#include 
#include 
#undef ReadArgs
#undef AROS_LH3
#define AROS_LH3(t,fn,a1,a2,a3,bt,bn,o,lib)     t fn (a1,a2,a3)
#undef AROS_LHA
#define AROS_LHA(t,n,r)                   t n
#undef AROS_LIBFUNC_INIT
#define AROS_LIBFUNC_INIT
#undef AROS_LIBBASE_EXT_DECL
#define AROS_LIBBASE_EXT_DECL(bt,bn)
#undef AROS_LIBFUNC_EXIT
#define AROS_LIBFUNC_EXIT
#include 
#include 
#include 

#include 

char cmlargs[] = "TEST/A";

char usage[] =
   "This is exthelp for test\n"
   "Enter something";

#define CML_TEST 0
#define CML_END  1

LONG cmlvec[CML_END];

int main(int argc, char **argv)
{
    struct RDArgs *rdargs;

    if( (rdargs = AllocDosObject(DOS_RDARGS, NULL)))
    {
	rdargs->RDA_ExtHelp = usage; /* FIX: why doesn't this work? */

	if(!(ReadArgs(cmlargs, cmlvec, rdargs)))
	{
	    PrintFault(IoErr(), "AROS boot");
	    FreeDosObject(DOS_RDARGS, rdargs);
	    exit(RETURN_FAIL);
	}
    }
    else
    {
	PrintFault(ERROR_NO_FREE_STORE, "AROS boot");
	exit(RETURN_FAIL);
    }

    FreeArgs(rdargs);
    FreeDosObject(DOS_RDARGS, rdargs);

    return 0;
} /* main */

SEE ALSO
FreeArgs(), Input()
INTERNALS
HISTORY
27.03.1997 digulla
Finished test code
26.03.1997 digulla
First steps to debug ReadArgs()
13.02.1997 digulla
Polish

Bugfix: If there is no buffer, read from me_Arguments, too

27.01.1997 ldp
Polish
09.12.1996 aros
Added empty templates for all missing functions

Moved #include's into first column

14.11.1996 aros
Some more changes
24.10.1996 aros
Use the official AROS macros over the __AROS versions.
13.09.1996 digulla
Use IPTR
16.08.1996 digulla
Fixed bug in docs. Bugfix in code is still pending.
13.08.1996 digulla
Replaced <dos/dosextens.h> by "dos_intern.h" or added "dos_intern.h" Replaced __AROS_LA by __AROS_LHA
01.08.1996 digulla
Added standard header for all files
28.07.1996 digulla
Initial revision
28.07.1996 digulla
First CVS version of AROS